﻿/*
//������Ķ�ȡ


*/


#ifndef __TRAPMASTER_COMMON_EXCELUNIT_H_
#define __TRAPMASTER_COMMON_EXCELUNIT_H_

#include "../CommonDef.h"
#include <map>
#include <string>
#include <vector>

dn_namespace_beg

class ExcelTable;
struct ExcelLine;

typedef std::map<uint32, char*>						ExcelSingleData;
typedef std::map<uint32, std::vector<char*>* >		ExcelArrayData;
typedef std::map<uint32, ExcelLine*>				ExcelLineMap;



struct ExcelLine
{
public:
	ExcelLine();
	ExcelLine(ExcelTable* pT,int idx);
	~ExcelLine();

	bool 		GetInt(int Col,int& Output );
	bool		GetFloat(int Col,float& Output);
	bool		GetStr(int Col,std::string& Output);
	
	bool 		GetArrayInt(int Col,std::vector<int>& Output);
	bool		GetArrayFloat(int Col,std::vector<float>& Output);
	bool		GetArrayStr(int Col,std::vector<std::string>& Output);
	int			GetArraySize(int Col);

	bool 		GetEXDValue(int Col,int& Output )						{return GetInt(Col,Output );}
	bool		GetEXDValue(int Col,float& Output)						{return GetFloat(Col,Output );}
	bool		GetEXDValue(int Col,std::string& Output)				{return GetStr(Col,Output );}
	
	bool 		GetEXDValue(int Col,std::vector<int>& Output)			{return GetArrayInt(Col,Output );}
	bool		GetEXDValue(int Col,std::vector<float>& Output)		{return GetArrayFloat(Col,Output );}
	bool		GetEXDValue(int Col,std::vector<std::string>& Output)	{return GetArrayStr(Col,Output );}


public:
	uint32					ID;
	uint32					Index;

	ExcelSingleData			SingleData;
	ExcelArrayData			ArrayData;

	ExcelTable*				pTable;

};


class ExcelTable
{
	struct ExcelLineInfo
	{
		ExcelLineInfo()
		{
			KeyCol=0;
		}

		int					KeyCol;
		std::vector<int>	TypeInfo;
		std::vector<bool>	IsLoad;
	};


public:
	ExcelTable();
	~ExcelTable();

	bool	LoadTable(const std::string& FilePath,const std::string& FileName);
	void	UnLoadTable();

	ExcelLine* Get(uint32 index);
	ExcelLine* Find(uint32 id);
	int		   Size();

public:
	ExcelLineMap	LineMap_Index;
	ExcelLineMap	LineMap_ID;
	ExcelLineInfo	LineInfo;

};


class ExcelGlobal
{
public:
	ExcelGlobal();
	~ExcelGlobal();

	static		ExcelGlobal& Instance();


public:
	static std::map<std::string, int>	ExcelType;

private:
	static ExcelGlobal* _inst;

};




dn_namespace_end




#endif

